//
//  DiceRollerController.m
//  This file is part of D&D Manager
//
//  Created by Matthew Hutton on 14/02/2007.
//
//
//D&D Manager, a D&D Character and battle management program.
//Copyright (C) 2007, Matthew Hutton
//
//This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License along with this program; if not, write to:
//The Free Software Foundation, Inc.,
//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

#import "DiceRollerController.h"
#import "RandomNumbers.h"
@implementation DiceRollerController
-(id)init{
	[super initWithWindowNibName:@"DiceRoller"];
	return self;
}
-(IBAction)rollDice:(id)sender{
	//NSLog(@"self=%@, noOfDice delegate=%@",self,[noOfDice delegate]);
	int no;
	int si;
	int bon;
	if([diceOptions selectedColumn]==0){
		no=1;
		si=20;
		bon=0;
	}else if([diceOptions selectedColumn]==1){
		no=1;
		si=100;
		bon=0;
	}else{
		no=[noOfDice intValue];
		si=[sizeOfDice intValue];
		bon=[bonusToDice intValue];
	}
	int i;
	int total=0;
	for(i=0;i<no;i++){
		total=total+[RandomNumbers randomIntUpTo:si];
	}
	[totalDisplay setStringValue:[[NSString alloc] initWithFormat:@"You rolled a %i+%i giving a total of %i",total,bon,total+bon]];
}
-(IBAction)closeRollDiceWindow:(id)sender{
	[rollDiceSheet orderOut:sender];
	[NSApp endSheet:rollDiceSheet];
}
-(void)controlTextDidChange:(NSNotification *)aNotification{
	if([[aNotification object] isEqualTo:noOfDice] || [[aNotification object] isEqualTo:sizeOfDice] || [[aNotification object] isEqualTo:bonusToDice]){
		[diceOptions selectCellAtRow:0 column:2];
	}
}
@end
